import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { Subject } from 'rxjs';
import { filter, map, startWith } from 'rxjs/operators';

@Component({
	selector: 'm-task',
	templateUrl: './task.component.html',
	styleUrls: ['./task.component.scss'],
})
export class TaskComponent implements OnInit {
	url = new Subject();

	navs = [
		{
			label: '执行中',
			link: '/task/running',
		},
		{
			label: '周期任务',
			link: '/task/schedule',
		},
		{
			label: '历史任务',
			link: '/task/history',
		},
	];
	findFirstChild = (route: ActivatedRoute) => (!route.firstChild ? route : this.findFirstChild(route.firstChild));
	hideNav$ = this.router.events.pipe(
		filter(event => event instanceof NavigationEnd), // 全局路由变动
		startWith(null),
		map(() => this.findFirstChild(this.route)), // 遍历最上层路由
		map(route => route.snapshot.data['hide_nav']), // 取出路由数据
	);
	constructor(private route: ActivatedRoute, private router: Router) {}

	ngOnInit() {}
}
